/**
 * 
 * @param  
 * @return {String}     
 */
exports.timeFormat = function(date) {
  var date = new Date(date);
  var time = new Date().getTime() - date.getTime(); 
  if (time < 0) {
    return '';
  } else if (time / 1000 < 60) {
    return parseInt((time / 1000)) + '秒前';
  } else if ((time / 60000) < 60) {
    return parseInt((time / 60000)) + '分钟前';
  } else if ((time / 3600000) < 24) {
    return parseInt(time / 3600000) + '个小时前';
  } else if ((time / 86400000) < 31) {
    return parseInt(time / 86400000) + '天前';
  } else if ((time / 2592000000) < 12) {
    return parseInt(time / 2592000000) + '个月前';
  } else {
    return parseInt(time / 31536000000) + '年前';
  }
}

/**
 * 
 * @param  {String} url 
 * @return {String}     
 */
exports.prefixUrl = function(url) {
  var reg = /^\/user\//;
  if (!reg.test(url)) return false;

  return '#!' + url;
}

/**
 *
 * @param  {String} tab 
 * @return {String}     
 */
exports.translateTab = function(tab) {
  switch (tab) {
    case 'share':
      return '分享';
      break;
    case 'ask':
      return '问答';
      break;
    case 'job':
      return '招聘';
      break;
  }
}


exports.saveLocalItem = function(key, value) {
  sessionStorage.setItem(key, value);
}

exports.getLocalItem = function(key) {
  return sessionStorage.getItem(key);
}

exports.removeLocalItem = function(key) {
  return sessionStorage.removeItem(key);
}
